package cn.tedu.csmall.stock.webapi.quartz.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//因为交换机路由key和队列的绑定关系最终交由SpringBoot管理
//所以当前类要设置为Spring配置类
@Configuration
public class RabbitMQConfiguration {
        //声明一个交换机名称,一个路由key名称,一个队列名称

    public static final String STOCK_EX="stock_ex";
    public static final String STOCK_ROUT="stock_rout";
    public static final String STOCK_QUEUE="stock_queue";

    //声明队列对象,保存到Spring容器中
    @Bean
    public Queue stockQueue(){
        return new Queue(STOCK_QUEUE);
    }

    //声明交换机对象,保存到Spring容器中
    @Bean
    public DirectExchange stockDirectExchange(){
        return new DirectExchange(STOCK_EX);
    }

    //由路由key保存交换机和队列的关系,也保存在Spring容器中

    @Bean
    public Binding stockBinding(){
        return BindingBuilder.bind(stockQueue()).to(stockDirectExchange()).with(STOCK_ROUT);
    }


}
